#include "AbsUI/UICommandRegistry.hpp"
#include <cassert>

namespace AbsUI
{


UICommandRegistry::~UICommandRegistry()
{

}

// ---------------------------------------------------------------------------------------------------------------------

void UICommandRegistry::registerCommand( const std::string& cmdID, UICommand* uiCommand )
{
	assert( !this->isCommandRegistered( cmdID));
	assert( NULL != uiCommand);
	registeredCommands_.insert( std::make_pair( cmdID, uiCommand));
}

// ---------------------------------------------------------------------------------------------------------------------

bool UICommandRegistry::isCommandRegistered( const std::string& cmdID ) const
{
	return registeredCommands_.end() != registeredCommands_.find( cmdID);
}

// ---------------------------------------------------------------------------------------------------------------------

UICommand& UICommandRegistry::command( const std::string& cmdID )
{
	assert( this->isCommandRegistered( cmdID));
	return *registeredCommands_.find( cmdID)->second;
}

// ---------------------------------------------------------------------------------------------------------------------

const UICommand& UICommandRegistry::command( const std::string& cmdID ) const
{
	assert( this->isCommandRegistered( cmdID));
	return *registeredCommands_.find( cmdID)->second;
}

// ---------------------------------------------------------------------------------------------------------------------

void UICommandRegistry::registerMenu( const std::string& menuID, QMenu* pMenu )
{
	assert( !this->isMenuRegistered( menuID));
	assert( NULL != pMenu);
	registeredMenus_.insert( std::make_pair( menuID, pMenu));
}

// ---------------------------------------------------------------------------------------------------------------------

bool UICommandRegistry::isMenuRegistered( const std::string& menuID ) const
{
	return registeredMenus_.end() != registeredMenus_.find( menuID);
}

// ---------------------------------------------------------------------------------------------------------------------

void UICommandRegistry::registerToolBar( const std::string& toolbarID, QToolBar* pToolBar )
{
	assert( NULL != pToolBar);
	assert( !this->isToolbarRegistered( toolbarID));
	registeredToolbars_.insert( std::make_pair( toolbarID, pToolBar));
}

// ---------------------------------------------------------------------------------------------------------------------

bool UICommandRegistry::isToolbarRegistered( const std::string& toolbarID ) const
{
	return registeredToolbars_.end() != registeredToolbars_.find( toolbarID);
}

// ---------------------------------------------------------------------------------------------------------------------

QMenu& UICommandRegistry::menu( const std::string& menuID )
{
	assert( this->isMenuRegistered( menuID));
	return *registeredMenus_.find( menuID)->second;
}

// ---------------------------------------------------------------------------------------------------------------------

const QMenu& UICommandRegistry::menu( const std::string& menuID ) const
{
	assert( this->isMenuRegistered( menuID));
	return *registeredMenus_.find( menuID)->second;
}

// ---------------------------------------------------------------------------------------------------------------------

QToolBar& UICommandRegistry::toolbar( const std::string& toolbarID )
{
	assert( this->isToolbarRegistered( toolbarID));
	return *registeredToolbars_.find( toolbarID)->second;
}

// ---------------------------------------------------------------------------------------------------------------------

const QToolBar& UICommandRegistry::toolbar( const std::string& toolbarID ) const
{
	assert( this->isToolbarRegistered( toolbarID));
	return *registeredToolbars_.find( toolbarID)->second;
}

} // namespace AbsUI
